/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package zone;

import JavaClass.ActionAll;
import Main.ExpoManagerMain;
import check.check;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Mai Lan
 */
public class ZoneAction {
    public static  void loadZone(JTable tbzone){
        Vector zonecp=new Vector();
        Vector zonefeil=new Vector();
           zonecp.clear();
            zonecp.add("ID");
            zonecp.add("NameZone");
            zonecp.add("NumberBooth");
            zonecp.add("Money");
            zonecp.add("SizeZone");
            zonecp.add("Status");
           zonefeil.clear();
            zonefeil.add("ID");
            zonefeil.add("NameZone");
            zonefeil.add("NumberBooth");
            zonefeil.add("Money");
            zonefeil.add("SizeZone");
            zonefeil.add("Status");
           ActionAll.LoadInfor(zonecp, tbzone, zonefeil, "Zone");

    }
    public static  void insertZone(JTable tblistzone,JTextField txtNameZone,JTextField txtNumbooth,JTextField txtMoney,JTextField txtsizeZone,JTextArea teaZone){
      
            try {
                boolean checkReady=check.checkReadlyData("Zone", "NameZone" , txtNameZone, ExpoManagerMain.conn);
                if(checkReady==false){
                    return;

                }
                String sqlInZone = "Insert into Zone (NameZone,NumberBooth,Money,SizeZone,Status) values(?,?,?,?,?)";
                PreparedStatement psInZone = ExpoManagerMain.conn.prepareStatement(sqlInZone);
                psInZone.setString(1, txtNameZone.getText().trim());
                psInZone.setString(2, txtNumbooth.getText().trim());
                psInZone.setString(3, txtMoney.getText().trim());
                psInZone.setString(4, txtsizeZone.getText().trim());
                psInZone.setString(5, teaZone.getText().trim());
                psInZone.executeUpdate();
               
                ZoneAction.loadZone(tblistzone);

            } catch (SQLException ex) {
                Logger.getLogger(ZoneAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        
    }
     public static  void UpZone(JTable tblistzone,JTextField txtNameZone,JTextField txtNumbooth,JTextField txtMoney,JTextField txtsizeZone,JTextArea teaZone){
        if(tblistzone.isCellSelected(tblistzone.getSelectedRow(), tblistzone.getSelectedColumn())==false){
                JOptionPane.showMessageDialog(null, "Please choice information want to edit on list");
                return;
        }
       
            try {

                int n = tblistzone.getSelectedRow();
                String Id = (String) tblistzone.getValueAt(n, 0);
                String sqlUp = "Update Zone set NameZone='" + txtNameZone.getText() + "',NumberBooth=" + txtNumbooth.getText().trim() + "," + "Money=" + txtMoney.getText().trim() + ",SizeZone=" + txtsizeZone.getText().trim() + ",Status='" + teaZone.getText().trim() + "'where ID=" + Id;
                Statement stIp = ExpoManagerMain.conn.createStatement();
                stIp.executeUpdate(sqlUp);
                ZoneAction.loadZone(tblistzone);
             

            } catch (SQLException ex) {
                Logger.getLogger(Zone.class.getName()).log(Level.SEVERE, null, ex);
            }   
        
    }
     public static  void Del(JTable tbzone){
       ActionAll.deleteInfor(tbzone, "Zone", "ID");
       ZoneAction.loadZone(tbzone);
    }
  
}
